<!--
 * @Author: 菅书繎 2032642089@qq.com
 * @Date: 2025-09-11 08:40:50
 * @LastEditors: 菅书繎 2032642089@qq.com
 * @LastEditTime: 2025-09-17 11:42:55
 * @FilePath: \大三上 前端\city\src\pages\components\Bottom3.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
    <div>
        <Title :title="title"></Title>
          {{ ed }}
        <!-- 提供图表容器 -->
        <div ref="bottom3" style="height: 150px;margin-top:10px"></div>
    </div>
</template>
<script>
import { DualAxes } from '@antv/g2plot';
import { get } from '@/utils/request';
import moment from 'moment';
import { mapState } from 'vuex';
export default{
    data(){
        return{
            title: '实时风力显示',
           dulData:[],
            params: {
                page: 1,
                pageSize: 50
            },
            dualAxes: null
        }

    },
    computed: {
        ...mapState(['ed'])
    },
    //侦听器 侦听数据
    watch: {
        ed: {
            handler(n, o) {
                //根据设备信息重新查询数据，重新渲染图表
                this.params.engineer_id = n.engineer_id;
                this.params.device_id = n.device_id;
                this.getEmpData();
                //根据最新获取的数据重新渲染图表
                this.dualAxes.changeData([this.dulData,this.dulData]);
            },

            //深度监听
            deep: true
        }
        },
    methods:{
        dulPhoto(){
            this.dualAxes = new DualAxes(this.$refs.bottom3, {
                data: [this.dulData,this.dulData],
                xField: 'insert_time',
                yField: ['wind_speed', 'wind_direction'],
                geometryOptions: [
                    {
                        geometry: 'column',
                    },
                    {
                        geometry: 'line',
                        lineStyle: {
                            lineWidth: 2,
                        },
                    },
                ],
            });

            this.dualAxes.render();

        },
        async getEmpData() {
            let res = await get('/dashboard/pageQueryTodayData', this.params);
            console.log(res,"bottom3");
            let temp = [];
            res.data.list.forEach((item, index, arr) => {
                arr[0].wind_speed = 20;
                item.insert_time = moment(item.insert_time).format("HH:mm");
                if (index % 5 == 0) {
                    temp.push(arr[index])
                }
            });
            this.dulData = temp;
        }
    },
    async mounted(){
        await this.getEmpData();
        this.dulPhoto();

    }

    }

    
</script>
<style lang="less" scoped>
    
</style>